package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.DesignSchemeImage;
import com.ruoyi.system.mapper.DesignSchemeImageMapper;
import com.ruoyi.system.service.DesignSchemeImageService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 设计方案图片表Service实现类
 */
@Service
public class DesignSchemeImageServiceImpl extends ServiceImpl<DesignSchemeImageMapper, DesignSchemeImage> implements DesignSchemeImageService {

    /**
     * 根据方案ID查询所有图片
     */
    @Override
    public List<DesignSchemeImage> selectBySchemeId(Long schemeId) {
        return baseMapper.selectBySchemeId(schemeId);
    }

    @Override
    public List<DesignSchemeImage> batchSelectBySchemeIds(List<Long> schemeIds) {
        return baseMapper.batchSelectBySchemeIds(schemeIds);
    }

    /**
     * 根据方案ID和空间类型查询图片
     */
    @Override
    public List<DesignSchemeImage> selectBySchemeIdAndSpaceType(Long schemeId, String spaceType) {
        return baseMapper.selectBySchemeIdAndSpaceType(schemeId, spaceType);
    }

    /**
     * 检查同一方案同一空间下是否存在相同文件名
     */
    @Override
    public boolean checkFileNameExists(Long schemeId, String spaceType, String fileName) {
        int count = baseMapper.checkFileNameExists(schemeId, spaceType, fileName);
        return count > 0;
    }

    /**
     * 更新图片排序
     */
    @Override
    @Transactional
    public boolean updateImageSort(List<DesignSchemeImage> images) {
        if (images == null || images.isEmpty()) {
            return true;
        }

        for (DesignSchemeImage image : images) {
            baseMapper.updateById(image);
        }
        return true;
    }
}
